package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.pojo.Permission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionDao permissionDao;

    /**
     *  根据id 回显检查项目数据
     *
     * @return
     */
    public Permission findPermissionByid(Integer id) {
        return permissionDao.findPermissionByid(id);

    }
    /**
     * 分页查询
     * @param currentPage
     * @param pageSize
     * @param queryString
     * @return
     */
    public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage,pageSize);
        Page<Permission> page = permissionDao.selectByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 新建
     * @param permission
     */
    public void add(Permission permission) {
        permissionDao.addPermission(permission);

    }

    /**
     * 删除
     * @param id
     */
    public void delete(Integer id){
        permissionDao.deletePermission(id);
    }


    /**
     *  更新权限
     */
    public void update(Permission permission) {
        permissionDao.update(permission);
    }

    /**
     *  检测所有项目
     * @return
     */
    public List<Permission> finAllPermission() {
        return  permissionDao.finAllPermission();
    }

}
